from django.db import models
from datetime import datetime


# from django.contrib.auth.models import AbstractUser

# Create your models here.

# 产品信息表
class ProductInfo(models.Model):
    pro_name = models.CharField('产品名称', max_length=50)
    pro_create_date = models.DateTimeField('创建时间', default=datetime.now)
    pro_comment = models.TextField('产品描述', max_length=255)

    class Meta:
        verbose_name = '产品信息'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.pro_name

# 组织信息表
class OrganizationInfo(models.Model):
    org_name=models.CharField('组织名称',max_length=25)

    class Meta:
        verbose_name = '组织信息'
        verbose_name_plural = verbose_name

# 环境信息表
class EnvInfo(models.Model):
    organization_choices = (
        (1, '南京研发'),
        (2, '云嘉云'),
        (3, '江苏高院'),
        (4, '浙江高院'),
        (5, '福建高院'),
        (6, '北京高院')
    )

    category_choices = (
        (1, '开发环境'),
        (2, '测试环境'),
        (3, '演示环境'),
        (4, '现场UAT环境'),
        (5, '现场生产环境')
    )

    cluster_choices = (
        (1, '单机'),
        (2, '双机'),
        (3, '集群')
    )

    env_app_name = models.CharField('应用名称', max_length=50)
    pro_name = models.ForeignKey('ProductInfo', verbose_name='产品名称', on_delete=models.CASCADE)
    env_organization = models.IntegerField('环境分组', choices=organization_choices, default=1)
    env_category = models.IntegerField('环境分类', choices=category_choices, default=1)
    env_is_cluster = models.IntegerField('是否集群', choices=cluster_choices, default=1)
    env_IP = models.GenericIPAddressField('IP地址', max_length=32)
    env_port = models.IntegerField('端口')
    env_owner_user = models.CharField('所属用户', max_length=50)
    env_dir = models.CharField('目录', max_length=255, null=True, blank=True)
    env_web_access = models.URLField('web访问地址', max_length=255, null=True, blank=True)
    env_create_date = models.DateTimeField('创建时间', default=datetime.now)
    env_comment = models.TextField('环境描述', max_length=255, null=True, blank=True)

    class Meta:
        verbose_name = '环境信息'
        verbose_name_plural = verbose_name
